/*
 * @Author: yuan-3-07 2144849287@qq.com
 * @Date: 2023-02-19 16:43:05
 * @LastEditors: yuan-3-07 2144849287@qq.com
 * @LastEditTime: 2023-02-23 19:10:43
 * @FilePath: \fitness-app\fitness03\src\utils\dom.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * DOM 操作封装
 */

//引入local.js
let local=require('./local.js');

// 1.封装获取单个节点
function getEle(selector) {
  return document.querySelector(selector);
}

// 2.多个节点
function getEles(selector) {
  return document.querySelectorAll(selector);
}

// 文档加载事件
function ready(cb) {
  window.addEventListener("DOMContentLoaded", function () {
    cb();
  });
}

// 封装页脚
function getFooter(obj) {
  document.body.innerHTML += `
    <footer>
    <ul>
        <li> 
            <a href="home.html"  class="${obj == "home" ? "active" : ""}">
              <span class="iconfont icon-shouye2"></span>
            <p>首页</p>  
            </a>
            
        </li>
        <li>
            <a href="sports.html" class="${obj == "sports" ? "active" : ""}">
                <span class="iconfont icon-shouye1"></span>
            <p>运动</p>
            </a>
           
        </li>
        <li>
            <a href="circle.html" class="${obj == "circle" ? "active" : ""}">
                <span class="iconfont icon-quanzi1
                "></span>
            <p>圈子</p>
            </a>
           
        </li>
        <li>
            <a href="my.html" class="${obj == "my" ? "active" : ""}">
               <span class="iconfont icon-wode-wodefensi"></span>
            <p>我的</p> 
            </a>
           
        </li>
    </ul>
</footer>


    `;
}


//封装判定是否登录
/*如果有登录,可以去给到的页面,如果没有登录,不能去指定页面,必需登录后,才能访问*/
function isLogin() {
  //1.获取 token
  let token = local.get("tk");
 

  //2.判定  没有token,跳转到登录,有token,直接放行
  if (!token) {
    location.href = "login.html";
  }
  console.log(token);
}

// 暴露
module.exports = {
  getEle,
  getEles,
  ready,
  getFooter,
  isLogin
};
